package com.zcx.qshop.adapter;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.qshop.R;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.conn.JsonEvaluatelistAsyGet;
import com.zcx.qshop.view.CommodityDetailStartView;

import java.util.List;

/**
 * Created by Administrator on 2015/8/31 0031.
 */
public class CommodityDetailAdapter extends QSAdapter<JsonEvaluatelistAsyGet.Info.Evaluate> {

    private LayoutInflater layoutInflater;

    public CommodityDetailAdapter(Context context, List<JsonEvaluatelistAsyGet.Info.Evaluate> objects) {

        super(context, objects);

        layoutInflater = ((Activity)context).getLayoutInflater();

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        JsonEvaluatelistAsyGet.Info.Evaluate evaluate = getItem(position);

        ViewHolder viewHolder;

        if(convertView == null){

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), QSApplication.ScaleScreenHelper.loadView((ViewGroup) layoutInflater.inflate(R.layout.item_commodity_detail, null)));

            convertView.setTag(viewHolder);

        }else{

            viewHolder = (ViewHolder) convertView.getTag();

        }

        viewHolder.img.setImageURI(Uri.parse(evaluate.picurl));

        viewHolder.title.setText(evaluate.name);

        viewHolder.commodityDetailStartView.setSelect(Integer.valueOf(evaluate.start));

        viewHolder.content.setText(evaluate.info);

        viewHolder.reply.setText(evaluate.recontent);

        viewHolder.reply.setVisibility(evaluate.recontent.equals("") ? View.GONE : View.VISIBLE);

        return convertView;

    }

    private class ViewHolder{

        @BoundView(R.id.item_commodity_detail_img) private SimpleDraweeView img;

        @BoundView(R.id.item_commodity_detail_title) private TextView title;

        @BoundView(R.id.item_commodity_detail_start_view) private CommodityDetailStartView commodityDetailStartView;

        @BoundView(R.id.item_commodity_detail_content) private TextView content;

        @BoundView(R.id.item_commodity_detail_reply) private TextView reply;

    }

}
